home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / c / memchr < prev    next >
Text File  |  1996-11-09  |  1KB  |  57 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/c/RCS/memchr,v $
  4.  * $Date: 1996/04/19 21:26:42 $
  5.  * $Revision: 1.1 $
  6.  * $State: Rel $
  7.  * $Author: simon $
  8.  *
  9.  * $Log: memchr,v $
  10.  * Revision 1.1  1996/04/19 21:26:42  simon
  11.  * Initial revision
  12.  *
  13.  ***************************************************************************/
  14.  
  15. static const char rcs_id[] = "$Id: memchr,v 1.1 1996/04/19 21:26:42 simon Rel $";
  16.  
  17. #include <string.h>
  18.  
  19. void *
  20. memchr (register const void *s, register int c, register size_t n)
  21.  
  22. {
  23.   register unsigned char *_s = (unsigned char *) s;
  24.  
  25.   while (n & 0x07)
  26.     {
  27.       n--;
  28.       if (*_s++ == c)
  29.     {
  30.     ret:return ((void *) (--_s));
  31.     }
  32.     }
  33.   n >>= 3;
  34.   while (n)
  35.     {
  36.       n--;
  37.       if (*_s++ == c)
  38.     goto ret;
  39.       if (*_s++ == c)
  40.     goto ret;
  41.       if (*_s++ == c)
  42.     goto ret;
  43.       if (*_s++ == c)
  44.     goto ret;
  45.       if (*_s++ == c)
  46.     goto ret;
  47.       if (*_s++ == c)
  48.     goto ret;
  49.       if (*_s++ == c)
  50.     goto ret;
  51.       if (*_s++ == c)
  52.     goto ret;
  53.     }
  54.  
  55.   return (0);
  56. }
  57.